//1.引入createRouter
import { createRouter, createWebHistory } from "vue-router";
import Home from "@/components/Home.vue";
import News from "@/components/News.vue";
import About from "@/components/About.vue";
import NewDetail from "@/components/NewDetail.vue";
//2.创建路由
const router = createRouter({
  history: createWebHistory(), //路由的工作模式
  routes: [
    // {
    //   path: "/",
    //   redirect: "/home",
    // },
    {
      name: "zhuye",
      path: "/home",
      component: Home,
    },
    {
      name: "xinwen",
      path: "/news",
      component: News,
      children: [
        {
          name: "detail",
          // path: "detail/:id/:title/:content",
          path: "detail",
          component: NewDetail,
          // props: true,//需要配合name跳转将params参数直接传递给组件
          //配合query参数，直接传递给组件
          props(route) {
            return route.query;
          },
          
        },
      ],
    },
    {
      name: "guanyu",
      path: "/about",
      component: About,
    },
  ],
});

//3.暴露路由
export default router;
